package com.adobe.coreUI.controls.whiteboardClasses
{
	import com.adobe.coreUI.controls.whiteboardClasses.shapes.WBArrowShapeFactory;
	import com.adobe.coreUI.controls.whiteboardClasses.shapes.WBHighlightAreaShapeFactory;
	import com.adobe.coreUI.controls.whiteboardClasses.shapes.WBMarkerShapeFactory;
	import com.adobe.coreUI.controls.whiteboardClasses.shapes.WBSimpleShape;
	import com.adobe.coreUI.controls.whiteboardClasses.shapes.WBSimpleShapeFactory;
	import com.adobe.coreUI.controls.whiteboardClasses.shapes.WBTextShapeFactory;
	import com.adobe.coreUI.localization.ILocalizationManager;
	import com.adobe.coreUI.localization.Localization;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.system.fscommand;
	import flash.xml.XMLNode;
	
	import mx.collections.ArrayCollection;
	import mx.collections.ICollectionView;
	import mx.collections.IViewCursor;
	import mx.collections.XMLListCollection;
	import mx.controls.Button;
	import mx.controls.TextInput;
	import mx.controls.menuClasses.IMenuDataDescriptor;
	import mx.controls.treeClasses.DefaultDataDescriptor;
	import mx.core.UIComponent;
	import mx.events.CollectionEvent;
	import mx.skins.halo.HaloBorder;

	[Event(name="toolBarClick", type="com.adobe.events.WBToolBarEvent")]
	
	/**
	 * @private
	 */
	public class WBShapesToolBar extends UIComponent
	{
		
		public static const COMMAND_UNDO:String = "undo";
		public static const COMMAND_REDO:String = "redo";
		public static const COMMAND_DELETE_SELECTED:String = "deleteSelected";
		public static const COMMAND_SAVE:String = "save";
		public static const COMMAND_PREPAGE:String = "prepage";
		public static const COMMAND_NEXTPAGE:String = "nextpage";
		
		[Embed (source = 'wbtoolBarIcons/tool_selection.png')]
		public static var ICON_SELECTION:Class;
		[Embed (source = 'wbtoolBarIcons/tool_arrow.png')]
		public static var ICON_ARROW:Class;
		[Embed (source = 'wbtoolBarIcons/tool_highlight_area.png')]
		public static var ICON_HIGHLIGHTER_PEN:Class;
		[Embed (source = 'wbtoolBarIcons/tool_highlight_rectangle.png')]
		public static var ICON_HIGHLIGHT_RECTANGLE:Class;
		[Embed (source = 'wbtoolBarIcons/tool_text.png')]
		public static var ICON_TEXT:Class;
		[Embed (source = 'wbtoolBarIcons/tool_line.png')]
		public static var ICON_LINE:Class;
		[Embed (source = 'wbtoolBarIcons/tool_shapes.png')]
		public static var ICON_SHAPES:Class;

		[Embed (source = 'wbtoolBarIcons/tool_ellipse.png')]
		public static var ICON_ELLIPSE:Class;
		[Embed (source = 'wbtoolBarIcons/tool_rectangle.png')]
		public static var ICON_RECTANLGE:Class;
		[Embed (source = 'wbtoolBarIcons/tool_rounded_rectangle.png')]
		public static var ICON_ROUNDED_RECTANGLE:Class;
		
		[Embed (source = 'wbtoolBarIcons/tool_undo.png')]
		public static var ICON_UNDO:Class;
		[Embed (source = 'wbtoolBarIcons/tool_redo.png')]
		public static var ICON_REDO:Class;
		[Embed (source = 'wbtoolBarIcons/tool_clear.png')]
		public static var ICON_DELETE_SHAPES:Class;
		[Embed (source = 'whiteboardAssets/toolBarIcons.swf#tool_save')]
		public static var ICON_SAVE:Class;
		[Embed (source = 'wbtoolBarIcons/tool_prepage.png')]
		public static var ICON_PREPAGE:Class;
		[Embed (source = 'wbtoolBarIcons/tool_nextpage.png')]
		public static var ICON_NEXTPAGE:Class;

	//	[Embed (source = 'wbtoolBarIcons/buttonBarOver.png')]
		//whiteboardAssets/toolBarIcons.swf#com.adobe.controls.buttonBarUp
		protected static var SKIN_UP:Class;
		[Embed (source = 'wbtoolBarIcons/buttonBarDown.png')]
		protected static var SKIN_OVER:Class;
		[Embed (source = 'wbtoolBarIcons/buttonBarOver.png')]
		protected static var SKIN_DOWN:Class;
		[Embed (source = 'wbtoolBarIcons/buttonBarDown.png')]
		//whiteboardAssets/toolBarIcons.swf#buttonBarSelected
		protected static var SKIN_SELECTED:Class;

		protected static const TITLE_HEIGHT:int = 10;
		protected static const SIDE_BUFFERS:int = 6;
		protected static const TITLE_WIDTH:int = 16;
		protected static const SIDE_BUFFERS2:int = 12;
		
		public var useTitleBar:Boolean = true;
		public var allowSave:Boolean = true;
		public var zhuanBar:Boolean = true;
		
		protected var _backgroundSkin:HaloBorder;
		//protected var _titleBar:Sprite;
		
		protected var _lm:ILocalizationManager;
		
		protected var _dataDescriptor:IMenuDataDescriptor = new DefaultDataDescriptor();
		protected var _rootModel:ICollectionView;
		protected var _invDataProviderChanged:Boolean = false;
		protected var _hasRoot:Boolean = false;
		protected var _selectedButt:Button;
		protected var _currentSubToolBar:WBShapesToolBar;
		
		protected var _controls:Array = new Array();
		protected var _buttonHeight:int = 25;
		protected var _buttonWidth:int = 30;

		public var markerFactory:IWBShapeFactory = new WBMarkerShapeFactory();
		public var textFactory:IWBShapeFactory = new WBTextShapeFactory();
		public var simpleShapeFactory:WBSimpleShapeFactory = new WBSimpleShapeFactory();
		public var arrowFactory:WBArrowShapeFactory = new WBArrowShapeFactory();
		public var highlightAreaFactory:WBSimpleShapeFactory = new WBHighlightAreaShapeFactory();

		protected var _wbCanvas:WBCanvas;
		protected var _tmpPropsBar:UIComponent;
		
		private var _iControl:String="1";
		private var pageInput:TextInput=null;
		
		public function set wbCanvas(p_canvas:WBCanvas):void
		{
			_wbCanvas = p_canvas;
			invalidateProperties();
//			_wbCanvas.addEventListener("selectionChange", switchToSelectionTool);
		}		

		public function tmpPropsBar(propsBar:UIComponent):void
		{
			_tmpPropsBar =propsBar;
		}
		/**
		 * 创建组件的子组件。例如，在 ComboBox 组件里包含一个 TextInput 控件以及一个 Button 控件作为其子组件。 
		 **/
		override protected function createChildren():void
		{
			print_debug("createChildren","start...");
			print_debug("createChildren measuredWidth:" + measuredWidth + " measuredHeight:" + measuredHeight);
			_backgroundSkin = new HaloBorder();
			setStyle("backgroundColor", 0xffffff);//0x9aa9b4);0x112391
			setStyle("borderStyle", "outset");
			setStyle("dropShadowEnabled", true);
			setStyle("shadowDistance", 3);
			setStyle("shadowDirection", "right");
			setStyle("color", 0xffffff);
			_backgroundSkin.styleName = this;
			//_backgroundSkin.setActualSize(482,46);////
			//_backgroundSkin.setActualSize(800,600);////
			addChild(_backgroundSkin);
		//	_titleBar = new Sprite();
		//	_titleBar.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
			//addChild(_titleBar);
			_lm = Localization.impl;
		}
		
		protected function startDragging(p_evt:MouseEvent):void
		{
			print_debug("startDragging","start...");
			stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging, false, 0, true);
			var rect:Rectangle;
			if (parent is UIComponent) {
				rect = new Rectangle(0,0,Math.max(0,parent.width-width),Math.max(0,parent.height-30));
			}
			startDrag(false, rect);
		}
		
		public  function setPageInfo(pageinof:String): void
		{
			if (pageInput!=null)
			{
				pageInput.text = pageinof;
			}
		}
		
		protected function stopDragging(p_evt:MouseEvent):void
		{
			print_debug("stopDragging","start...");
			stage.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);
			stopDrag();
		}
		
		//1 无权限 全不可用 不能选择
		//2 操作权限 翻页不可用
		//4 控制权限 所有操作
		public function wbControl(iCon:String):void{
			_wbCanvas.wbControl(iCon);///
			
			var iEnabled:Boolean = true;
			var iPage:Boolean =false;
			if (iCon=="1"){
				iEnabled=false;
				_wbCanvas.enableShapeSelection = false;
				_wbCanvas.currentShapeFactory = null;
				if (_selectedButt) {
						_selectedButt.selected = false;
				}

				
				//if (_currentSubToolBar) {
				//	Alert.show("toolbar:"+_currentSubToolBar);
				//	closeSubToolBar();
				//}
			}
			else if(iCon =="2"){
				_wbCanvas.enableShapeSelection = true;
				iPage = true;
			}
			else if(iCon =="4"){
				_wbCanvas.enableShapeSelection = true;
				iPage = true;
			}
			_iControl = iCon;
			///Alert.show("control:"+iCon +" - enabled:" + iEnabled +" - length:" +_controls.length);
			var initButton:String ="Selection Tool";
			for (var i:int=0; i<_controls.length; i++) {
				var b:Button = _controls[i] as Button;
				if (b) {
					///Alert.show(b.name +"-"+b.toolTip);//command
					if(b.toolTip.toLowerCase() ==initButton.toLowerCase()){
						//b.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
						//dispatchEvent(new WBToolBarEvent(WBToolBarEvent.TOOL_BAR_CLICK,b.data)); 
									
					}
					if(b.toolTip.toLowerCase() ==COMMAND_PREPAGE.toLowerCase() || b.toolTip.toLowerCase() == COMMAND_NEXTPAGE.toLowerCase()){
						//Alert.show("------- " + b.toolTip + "-------");
						b.enabled =iPage;					
					}else{
						b.enabled =iEnabled;
					}
				}
			}
		}
		
		override protected function commitProperties():void
		{
			print_debug("commitProperties","start...");
			if (!_rootModel) {
				var data:Object = 
					{children:
					[
						
						{type:"command", toolTip:_lm.getString("PrePage"), icon:ICON_PREPAGE, command:COMMAND_PREPAGE},
					//	{type:"label", text:_lm.getString("Tools")},
					    {type:"command", toolTip:_lm.getString("page"), icon:ICON_NEXTPAGE, command:COMMAND_NEXTPAGE},
						{type:"command", toolTip:_lm.getString("NextPage"), icon:ICON_NEXTPAGE, command:COMMAND_NEXTPAGE},
						{type:"tool", toolTip:_lm.getString("Selection Tool"), icon:ICON_SELECTION},
						{type:"tool", toolTip:_lm.getString("Arrow Tool"), shapeFactory:arrowFactory, shapeData:WBArrowShapeFactory.ARROW_HEAD, icon:ICON_ARROW},
						{type:"tool", toolTip:_lm.getString("Highlighter Pen Tool"), shapeFactory:markerFactory, shapeData:WBMarkerShapeFactory.HIGHLIGHTER, icon:ICON_HIGHLIGHTER_PEN},
						{type:"tool", toolTip:_lm.getString("Highlight Rectangle Tool"), shapeFactory:highlightAreaFactory, shapeData:WBSimpleShapeFactory.HIGHLIGHT_AREA, icon:ICON_HIGHLIGHT_RECTANGLE},
						{type:"tool", toolTip:_lm.getString("Text Tool"), shapeFactory:textFactory, icon:ICON_TEXT},
						//{type:"tool", toolTip:_lm.getString("Shapes"), icon:ICON_SHAPES},
				        {type:"tool", toolTip:_lm.getString("Line Tool"), icon:ICON_LINE, shapeFactory:arrowFactory, shapeData:WBArrowShapeFactory.NO_ARROW_HEAD},
						{type:"tool", toolTip:_lm.getString("Ellipse Tool"), shapeFactory:simpleShapeFactory, shapeData:WBSimpleShape.ELLIPSE, icon:ICON_ELLIPSE},						
					    {type:"tool", toolTip:_lm.getString("Rectangle Tool"), shapeFactory:simpleShapeFactory, shapeData:WBSimpleShape.RECTANGLE, icon:ICON_RECTANLGE},						
						{type:"tool", toolTip:_lm.getString("Rounded Rectangle Tool"), shapeFactory:simpleShapeFactory, shapeData:WBSimpleShape.ROUNDED_RECTANGLE, icon:ICON_ROUNDED_RECTANGLE},
						//{type:"label", label:_lm.getString("Actions")},
						{type:"command", toolTip:_lm.getString("Undo"), icon:ICON_UNDO, command:COMMAND_UNDO},
						{type:"command", toolTip:_lm.getString("Redo"), icon:ICON_REDO, command:COMMAND_REDO},
						{type:"command", toolTip:_lm.getString("Delete Selected Shapes"), icon:ICON_DELETE_SHAPES, command:COMMAND_DELETE_SELECTED},
						{type:"command", toolTip:_lm.getString("Save as File"), icon:ICON_SAVE, command:COMMAND_SAVE},

					]
					};

				processDP(data);
				_invDataProviderChanged = true;
			}

			if (_invDataProviderChanged) {
				_invDataProviderChanged = false;
				
				if (_currentSubToolBar) {
					closeSubToolBar();
				}
				for (var i:int=0; i<_controls.length; i++) {
					var b:Button = _controls[i] as Button;
					if (b) {
						b.removeEventListener(MouseEvent.CLICK, processClick);
					}
					if(_controls[i]){						
						removeChild(_controls[i]);
					}
				}
				_controls = new Array();
				
						
				var topLevel:ICollectionView;
	
	            var rootItem:* = _rootModel.createCursor().current;
	            if (rootItem != null &&
	                _dataDescriptor.isBranch(rootItem, _rootModel) &&
	                _dataDescriptor.hasChildren(rootItem, _rootModel))
	            {
	                // then get rootItem children
	                topLevel = _dataDescriptor.getChildren(rootItem, _rootModel);
	            } else {
	            	topLevel = _rootModel;
	            }
	
				var theY:int = (useTitleBar) ? TITLE_HEIGHT + 5 : 5;
				var theX:int = 5;
				
				var cursor:IViewCursor = topLevel.createCursor();
				var curr:Object = cursor.current;
				//var iCount:int =0;
				while (curr) {
					if (curr.shapeFactory) {
						var factory:IWBShapeFactory = curr.shapeFactory as IWBShapeFactory;
						// TODO : need to traverse child branches to reg factories
						if (_wbCanvas) {
							_wbCanvas.registerFactory(factory);
						}
					}
					
					if (curr.type=="label") {
						var lbl:TextInput = new TextInput();
						//lbl.width = 50;
						//lbl.setColor(0x112391);
						addChild(lbl);
						lbl.text = "1/1";
						
						measuredWidth = Math.max(measuredWidth, lbl.textWidth + 4 + 2*SIDE_BUFFERS);
						lbl.setActualSize(40, 20);
						if(zhuanBar){
							lbl.move(theX+3 , SIDE_BUFFERS2);
							_controls.push(lbl);
							theX += 40 + 8;
						}else{
							lbl.move(SIDE_BUFFERS, theY+3);
							_controls.push(lbl);
							theY += 25 + 8;
						}
					} else 
					
					
////						if(curr.type=="input"){
////					 	   var input:TextInput =new TextInput();
////					  	  addChild(input);
////					   	 input.text="1/2xcgddsfgdsfgdsgdsgdsgdsgdsgdsf";
////					   // continue;
////		
////						}
//					
//						else
					
					{
						if (curr.icon==ICON_SAVE && !allowSave) {
							cursor.moveNext();
							curr = cursor.current;
							continue
						}
						
						if (curr.toolTip=="page"){
							var lbl:TextInput = new TextInput();
						//lbl.width = 50;
						//lbl.setColor(0x112391);
						lbl.setStyle("color",0x112391);
						addChild(lbl);
						lbl.text = "1/1";
						pageInput = lbl;
						lbl.setActualSize(40, 25);
						if(zhuanBar){
							lbl.move(theX+3 , SIDE_BUFFERS2);
							_controls.push(lbl);
							theX += 40 + 8;
						}else{
							lbl.move(SIDE_BUFFERS, theY+3);
							_controls.push(lbl);
							theY += 25 + 8;
						}
							
						}
						else
						{
						
	
						var butt:Button = new Button();
					//	butt.setStyle("upSkin", SKIN_UP);
						butt.setStyle("overSkin", SKIN_OVER);
						butt.setStyle("downSkin", SKIN_DOWN);
						butt.setStyle("selectedUpSkin", SKIN_SELECTED);
						butt.setStyle("selectedOverSkin", SKIN_SELECTED);
						butt.setStyle("selectedDownSkin", SKIN_SELECTED);
						addChild(butt);	
						
						butt.styleName = "buttonBar";
						butt.setStyle("borderColor","#eaeaea");/**一级菜单的背景色*/
					//	borderColor: #901013;
						
						
						butt.toggle = (curr.type=="tool");
						butt.setActualSize(_buttonWidth, _buttonHeight);
						//butt.width = 30;
						//trace("commitProperties X:" + theX + " Y:" + SIDE_BUFFERS2 + " _buttonHeight:" + _buttonHeight +" _buttonWidth:" +_buttonWidth);
						//butt.setSize(_buttonWidth, _buttonHeight);
						if(zhuanBar){
							butt.move(theX,SIDE_BUFFERS2);
						}else{
							butt.move(SIDE_BUFFERS, theY);	
						}
						
						butt.data = curr;
						butt.addEventListener(MouseEvent.CLICK, processClick);
						_controls.push(butt);
						if (curr.icon) {
							butt.setStyle("icon", curr.icon);
						}
						if (curr.toolTip) {
							butt.toolTip = curr.toolTip;
						}

						if (_dataDescriptor.hasChildren(butt.data, _rootModel)) {
							// it's a sub-toolbar creator. 
							openSubToolBar(butt);
							closeSubToolBar();
						}
						if(zhuanBar){
							theX += butt.width+1;
						}else{
							theY += butt.height+1;
						}
						}
					}
					/*
					if(zhuanBar){
						measuredWidth = theX +5;
						if (measuredHeight<20) { 
							measuredHeight = _buttonHeight + SIDE_BUFFERS2 + 2;
						}
					}else{
						measuredHeight = theY+5;
						if (measuredWidth<20) { 
							measuredWidth = _buttonWidth + 2*SIDE_BUFFERS;
						}
					}
					//*/
					cursor.moveNext();
					curr = cursor.current;
					/*/
					iCount++;
					if(iCount >20){
						break;
					}
					//*/
				}
				print_debug("commitProperties measuredWidth:"+ measuredWidth + " measuredHeight:" + measuredHeight);
				//measuredHeight =measuredWidth;
				wbControl(_iControl);
			}
		}
		
		override protected function measure():void
		{
			print_debug("measure","start...");
		}
		
		override protected function updateDisplayList(p_w:Number, p_h:Number):void
		{
			print_debug("--updateDisplayList-- p_w:" + p_w + " p_h:" + p_h);
			var t_w:Number = p_w;
			var t_h:Number = p_h;
			
			if(p_h <1){
				t_w =478;
				t_h =46;
			}
			_backgroundSkin.setActualSize(p_w, p_h);
			
			var buttW:int = p_w - 2*SIDE_BUFFERS;
			if(buttW >0){
				for (var i:int=0; i<_controls.length; i++) {
					var b:Button = _controls[i] as Button;
					if (b) {
						print_debug("updateDisplayList buttW:" +buttW + " b.height:" + b.height);
						b.setActualSize(buttW, b.height);
					}
				}
			}
			
		/*	if (useTitleBar) {
				var g:Graphics = _titleBar.graphics;
				g.clear();		
				
				var gradMatr:Matrix = new Matrix();
				gradMatr.createGradientBox(t_w, TITLE_HEIGHT, Math.PI/2);			
				g.beginGradientFill(GradientType.LINEAR, [0x4C4C4C,0x393939],[1,1],[0,255],gradMatr);
				g.moveTo(1,TITLE_HEIGHT);
				g.lineStyle(1, 0x868686);			
				g.lineTo(1,1);
				g.lineTo(t_w-2,1);
				g.lineStyle(1,0x1C1C1C);
				g.lineTo(t_w-2,TITLE_HEIGHT);
				g.lineTo(1,TITLE_HEIGHT);
				g.endFill();			
			}*/
		}
		
		protected function closeSubToolBar():void
		{
			print_debug("closeSubToolBar","start...");
			if(_currentSubToolBar && this.parent.parent.contains(_currentSubToolBar)){
				this.parent.parent.removeChild(_currentSubToolBar);
				///_currentSubToolBar = null;				
			}
		}
		
		protected function openSubToolBar(p_button:Button):void
		{
			print_debug("openSubToolBar","start...");
			_currentSubToolBar = new WBShapesToolBar();
			_currentSubToolBar.dataProvider = _dataDescriptor.getChildren(p_button.data, _rootModel);
			_currentSubToolBar.useTitleBar = false;
			_currentSubToolBar.wbCanvas = _wbCanvas;
			this.parent.parent.addChild(_currentSubToolBar);
			_currentSubToolBar.validateNow();
			_currentSubToolBar.setActualSize(_currentSubToolBar.measuredWidth, _currentSubToolBar.measuredHeight);
		    _currentSubToolBar.setStyle("color","#ffffff");
			if(zhuanBar){
				//_currentSubToolBar.move(p_button.x-10, p_button.y+ p_button.height + 2);
				p_button.x=170;
				_currentSubToolBar.move(p_button.x-10, p_button.y	+ 15);
			}else{
				//_currentSubToolBar.move(p_button.x+p_button.width+2, p_button.y-10);
				p_button.x=170;
				_currentSubToolBar.move(p_button.x, p_button.y	+ 15);
			}
			
			if(_tmpPropsBar && this.parent.parent.contains(_tmpPropsBar)){
				this.parent.parent.removeChild(_tmpPropsBar);
			}
			////////////
		}
		
		protected function processClick(p_evt:Event):void
		{
			print_debug("processClick","start...[" + _iControl + "]");
			if(_iControl !="1"){
				var target:Button = p_evt.target as Button;
				if (target.data.type=="tool") {
					if (_currentSubToolBar) {
						closeSubToolBar();
					}
					if (_dataDescriptor.hasChildren(target.data, _rootModel)) {
						// it's a sub-toolbar creator. 
						openSubToolBar(target);
					} else {
						_wbCanvas.enableShapeSelection = (target.data.shapeFactory==null);
						var factory:IWBShapeFactory = target.data.shapeFactory as IWBShapeFactory;
						if (target.data.shapeData) {
							factory.shapeData = target.data.shapeData;
							this.parentApplication.sharpeclass=target.data.shapeData;//Application.application						
						}
						
						_wbCanvas.currentShapeFactory = factory;
					}
					if (_selectedButt) {
						_selectedButt.selected = false;
					}
					_selectedButt = target;
					_selectedButt.selected = true;
				} else if (target.data.type=="command") {
					var command:String = target.data.command;
					if (command==COMMAND_UNDO) {
						_wbCanvas.undo();
					} else if (command==COMMAND_REDO) {
						_wbCanvas.redo();
					} else if (command==COMMAND_DELETE_SELECTED) {
						_wbCanvas.removeSelectedShapes();
					} else if(command==COMMAND_PREPAGE) {
						if(_iControl =="4"){
							print_debug("processClick:"+COMMAND_PREPAGE);
							//Alert.show(COMMAND_PREPAGE);
							fscommand("page","pre");							
						}
					}  else if(command==COMMAND_NEXTPAGE) {
						if(_iControl =="4"){
							print_debug("processClick:"+COMMAND_NEXTPAGE);
							fscommand("page","next");
							//Alert.show(COMMAND_NEXTPAGE);							
						}
					} 
				} 
				//dispatchEvent(new WBToolBarEvent(WBToolBarEvent.TOOL_BAR_CLICK, target.data));				
			}

		}
		
		public function set dataProvider(p_data:Object):void
		{
			print_debug("dataProvider","start...");
	        if (_rootModel) {
//	            _rootModel.removeEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
	        }
	        //flag for processing in commitProps
	        processDP(p_data);
	        _invDataProviderChanged = true;
	        invalidateProperties();			
		}
		
		public function get dataProvider():Object
		{
			return _rootModel;
		}
		
		public function get dataDescriptor():IMenuDataDescriptor
		{
			return _dataDescriptor;
		}
		
		protected function collectionChangeHandler(p_evt:CollectionEvent):void
		{
			// TODO: rebuild!
		}
		
		protected function processDP(p_data:Object):void
		{
			print_debug("processDP","start...");
	        // handle strings and xml
	        if (typeof(p_data)=="string")
	            p_data = new XML(p_data);
	        else if (p_data is XMLNode)
	            p_data = new XML(XMLNode(p_data).toString());
	        else if (p_data is XMLList)
	            p_data = new XMLListCollection(p_data as XMLList);
	        
	        if (p_data is XML)
	        {
	            _hasRoot = true;
	            var xl:XMLList = new XMLList();
	            xl += p_data;
	            _rootModel = new XMLListCollection(xl);
	        }
	        //if already a collection dont make new one
	        else if (p_data is ICollectionView)
	        {
	            _rootModel = ICollectionView(p_data);

	            if (_rootModel.length == 1)
	            	_hasRoot = true;
	        }
	        else if (p_data is Array)
	        {
	            _rootModel = new ArrayCollection(p_data as Array);
	        }
	        //all other types get wrapped in an ArrayCollection
	        else if (p_data is Object)
	        {
	            _hasRoot = true;
	            // convert to an array containing this one item
	            var tmp:Array = [];
	            tmp.push(p_data);
	            _rootModel = new ArrayCollection(tmp);
	        }
	        else
	        {
	            _rootModel = new ArrayCollection();
	        }
		}
		
		private function print_debug(func:String,info:String=""):void{
			//Alert.show(""+func + " || " + info );
			trace("WBShapesToolBar.as || "+func + " || " + info );
		}
	}
}